/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is COID http service.
 *
 * The Initial Developer of the Original Code is
 * PosAm.
 * Portions created by the Initial Developer are Copyright (C) 2003
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 * Brano Kemen
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

#ifndef __COID_SERVICES_HTTPSERV_MIME__HEADER_FILE__
#define __COID_SERVICES_HTTPSERV_MIME__HEADER_FILE__

namespace coid {

////////////////////////////////////////////////////////////////////////////////
class MIME_REG
{
    struct MIME {
        charstr  ext;
        charstr  mime;

        bool operator < ( const token& str ) const
        {
            return ext < str;
        }
    };

    dynarray<MIME> _mime;

public:
    void add_mime( const char* ext, const char* mime )
    {
        MIME* pm = _mime.add_sortT(ext);
        pm->ext = ext;
        pm->mime = mime;
    }

    const charstr& find_mime( const token& ext ) const
    {
        static charstr _defmime = "text/plain";

        uints i = _mime.lower_boundT(ext);
        if( i < _mime.size()  &&  _mime[i].ext == ext )
            return _mime[i].mime;
        return _defmime;
    }

    MIME_REG()
    {
        add_mime( "",       "text/plain" );
        add_mime( "a",	    "application/octet-stream" );
        add_mime( "aab",	"application/x-authorware-bin" );
        add_mime( "aam",	"application/x-authorware-map" );
        add_mime( "aas",	"application/x-authorware-seg" );
        add_mime( "ai",	    "application/postscript" );
        add_mime( "aif",	"audio/x-aiff" );
        add_mime( "aifc",	"audio/x-aiff" );
        add_mime( "aiff",	"audio/x-aiff" );
        add_mime( "asc",	"text/plain" );
        add_mime( "asf",	"video/x-ms-asf" );
        add_mime( "asx",	"video/x-ms-asf" );
        add_mime( "au",	    "audio/basic" );
        add_mime( "avi",	"video/x-msvideo" );
        add_mime( "bcpio",	"application/x-bcpio" );
        add_mime( "bin",	"application/octet-stream" );
        add_mime( "bmp",	"image/bmp" );
        add_mime( "cdf",	"application/x-netcdf" );
        add_mime( "class",	"application/x-java-vm" );
        add_mime( "cpio",	"application/x-cpio" );
        add_mime( "cpt",	"application/mac-compactpro" );
        add_mime( "crl",	"application/x-pkcs7-crl" );
        add_mime( "crt",	"application/x-x509-ca-cert" );
        add_mime( "csh",	"application/x-csh" );
        add_mime( "css",	"text/css" );
        add_mime( "dcr",	"application/x-director" );
        add_mime( "dir",	"application/x-director" );
        add_mime( "djv",	"image/vnd.djvu" );
        add_mime( "djvu",	"image/vnd.djvu" );
        add_mime( "dll",	"application/octet-stream" );
        add_mime( "dms",	"application/octet-stream" );
        add_mime( "doc",	"application/msword" );
        add_mime( "dtd",	"text/xml" );
        add_mime( "dump",	"application/octet-stream" );
        add_mime( "dvi",	"application/x-dvi" );
        add_mime( "dxr",	"application/x-director" );
        add_mime( "eps",	"application/postscript" );
        add_mime( "etx",	"text/x-setext" );
        add_mime( "exe",	"application/octet-stream" );
        add_mime( "ez",	    "application/andrew-inset" );
        add_mime( "fgd",	"application/x-director" );
        add_mime( "fh",	    "image/x-freehand" );
        add_mime( "fh4",	"image/x-freehand" );
        add_mime( "fh5",	"image/x-freehand" );
        add_mime( "fh7",	"image/x-freehand" );
        add_mime( "fhc",	"image/x-freehand" );
        add_mime( "gif",	"image/gif" );
        add_mime( "gtar",	"application/x-gtar" );
        add_mime( "hdf",	"application/x-hdf" );
        add_mime( "hqx",	"application/mac-binhex40" );
        add_mime( "htm",	"text/html; charset=%s" );
        add_mime( "html",	"text/html; charset=%s" );
        add_mime( "ice",	"x-conference/x-cooltalk" );
        add_mime( "ief",	"image/ief" );
        add_mime( "iges",	"model/iges" );
        add_mime( "igs",	"model/iges" );
        add_mime( "iv",	    "application/x-inventor" );
        add_mime( "jar",	"application/x-java-archive" );
        add_mime( "jfif",	"image/jpeg" );
        add_mime( "jpe",	"image/jpeg" );
        add_mime( "jpeg",	"image/jpeg" );
        add_mime( "jpg",	"image/jpeg" );
        add_mime( "js",	    "application/x-javascript" );
        add_mime( "kar",	"audio/midi" );
        add_mime( "latex",	"application/x-latex" );
        add_mime( "lha",	"application/octet-stream" );
        add_mime( "lzh",	"application/octet-stream" );
        add_mime( "m3u",	"audio/x-mpegurl" );
        add_mime( "man",	"application/x-troff-man" );
        add_mime( "mathml",	"application/mathml+xml" );
        add_mime( "me",	    "application/x-troff-me" );
        add_mime( "mesh",	"model/mesh" );
        add_mime( "mid",	"audio/midi" );
        add_mime( "midi",	"audio/midi" );
        add_mime( "mif",	"application/vnd.mif" );
        add_mime( "mime",	"message/rfc822" );
        add_mime( "mml",	"application/mathml+xml" );
        add_mime( "mov",	"video/quicktime" );
        add_mime( "movie",	"video/x-sgi-movie" );
        add_mime( "mp2",	"audio/mpeg" );
        add_mime( "mp3",	"audio/mpeg" );
        add_mime( "mp4",	"video/mp4" );
        add_mime( "mpe",	"video/mpeg" );
        add_mime( "mpeg",	"video/mpeg" );
        add_mime( "mpg",	"video/mpeg" );
        add_mime( "mpga",	"audio/mpeg" );
        add_mime( "ms",	    "application/x-troff-ms" );
        add_mime( "msh",	"model/mesh" );
        add_mime( "mv",	    "video/x-sgi-movie" );
        add_mime( "mxu",	"video/vnd.mpegurl" );
        add_mime( "nc",	    "application/x-netcdf" );
        add_mime( "o",	    "application/octet-stream" );
        add_mime( "oda",	"application/oda" );
        add_mime( "ogg",	"application/x-ogg" );
        add_mime( "pac",	"application/x-ns-proxy-autoconfig" );
        add_mime( "pbm",	"image/x-portable-bitmap" );
        add_mime( "pdb",	"chemical/x-pdb" );
        add_mime( "pdf",	"application/pdf" );
        add_mime( "pgm",	"image/x-portable-graymap" );
        add_mime( "pgn",	"application/x-chess-pgn" );
        add_mime( "png",	"image/png" );
        add_mime( "pnm",	"image/x-portable-anymap" );
        add_mime( "ppm",	"image/x-portable-pixmap" );
        add_mime( "ppt",	"application/vnd.ms-powerpoint" );
        add_mime( "ps",	    "application/postscript" );
        add_mime( "qt",	    "video/quicktime" );
        add_mime( "ra",	    "audio/x-realaudio" );
        add_mime( "ram",	"audio/x-pn-realaudio" );
        add_mime( "ras",	"image/x-cmu-raster" );
        add_mime( "rdf",	"application/rdf+xml" );
        add_mime( "rgb",	"image/x-rgb" );
        add_mime( "rm",	    "audio/x-pn-realaudio" );
        add_mime( "roff",	"application/x-troff" );
        add_mime( "rpm",	"audio/x-pn-realaudio-plugin" );
        add_mime( "rss",	"application/rss+xml" );
        add_mime( "rtf",	"text/rtf" );
        add_mime( "rtx",	"text/richtext" );
        add_mime( "sgm",	"text/sgml" );
        add_mime( "sgml",	"text/sgml" );
        add_mime( "sh",	    "application/x-sh" );
        add_mime( "shar",	"application/x-shar" );
        add_mime( "silo",	"model/mesh" );
        add_mime( "sit",	"application/x-stuffit" );
        add_mime( "skd",	"application/x-koan" );
        add_mime( "skm",	"application/x-koan" );
        add_mime( "skp",	"application/x-koan" );
        add_mime( "skt",	"application/x-koan" );
        add_mime( "smi",	"application/smil" );
        add_mime( "smil",	"application/smil" );
        add_mime( "snd",	"audio/basic" );
        add_mime( "so",	    "application/octet-stream" );
        add_mime( "spl",	"application/x-futuresplash" );
        add_mime( "src",	"application/x-wais-source" );
        add_mime( "stc",	"application/vnd.sun.xml.calc.template" );
        add_mime( "std",	"application/vnd.sun.xml.draw.template" );
        add_mime( "sti",	"application/vnd.sun.xml.impress.template" );
        add_mime( "stw",	"application/vnd.sun.xml.writer.template" );
        add_mime( "sv4cpio","application/x-sv4cpio" );
        add_mime( "sv4crc",	"application/x-sv4crc" );
        add_mime( "svg",	"image/svg+xml" );
        add_mime( "svgz",	"image/svg+xml" );
        add_mime( "swf",	"application/x-shockwave-flash" );
        add_mime( "sxc",	"application/vnd.sun.xml.calc" );
        add_mime( "sxd",	"application/vnd.sun.xml.draw" );
        add_mime( "sxg",	"application/vnd.sun.xml.writer.global" );
        add_mime( "sxi",	"application/vnd.sun.xml.impress" );
        add_mime( "sxm",	"application/vnd.sun.xml.math" );
        add_mime( "sxw",	"application/vnd.sun.xml.writer" );
        add_mime( "t",	    "application/x-troff" );
        add_mime( "tar",	"application/x-tar" );
        add_mime( "tcl",	"application/x-tcl" );
        add_mime( "tex",	"application/x-tex" );
        add_mime( "texi",	"application/x-texinfo" );
        add_mime( "texinfo","application/x-texinfo" );
        add_mime( "tif",	"image/tiff" );
        add_mime( "tiff",	"image/tiff" );
        add_mime( "tr",	    "application/x-troff" );
        add_mime( "tsp",	"application/dsptype" );
        add_mime( "tsv",	"text/tab-separated-values" );
        add_mime( "txt",	"text/plain; charset=%s" );
        add_mime( "ustar",	"application/x-ustar" );
        add_mime( "vcd",	"application/x-cdlink" );
        add_mime( "vrml",	"model/vrml" );
        add_mime( "vx",	    "video/x-rad-screenplay" );
        add_mime( "wav",	"audio/x-wav" );
        add_mime( "wax",	"audio/x-ms-wax" );
        add_mime( "wbmp",	"image/vnd.wap.wbmp" );
        add_mime( "wbxml",	"application/vnd.wap.wbxml" );
        add_mime( "wm",	    "video/x-ms-wm" );
        add_mime( "wma",	"audio/x-ms-wma" );
        add_mime( "wmd",	"application/x-ms-wmd" );
        add_mime( "wml",	"text/vnd.wap.wml" );
        add_mime( "wmlc",	"application/vnd.wap.wmlc" );
        add_mime( "wmls",	"text/vnd.wap.wmlscript" );
        add_mime( "wmlsc",	"application/vnd.wap.wmlscriptc" );
        add_mime( "wmv",	"video/x-ms-wmv" );
        add_mime( "wmx",	"video/x-ms-wmx" );
        add_mime( "wmz",	"application/x-ms-wmz" );
        add_mime( "wrl",	"model/vrml" );
        add_mime( "wsrc",	"application/x-wais-source" );
        add_mime( "wvx",	"video/x-ms-wvx" );
        add_mime( "xbm",	"image/x-xbitmap" );
        add_mime( "xht",	"application/xhtml+xml" );
        add_mime( "xhtml",	"application/xhtml+xml" );
        add_mime( "xls",	"application/vnd.ms-excel" );
        add_mime( "xml",	"text/xml" );
        add_mime( "xpm",	"image/x-xpixmap" );
        add_mime( "xsl",	"text/xml" );
        add_mime( "xwd",	"image/x-xwindowdump" );
        add_mime( "xyz",	"chemical/x-xyz" );
        add_mime( "zip",	"application/zip" );
    }
};

}

#endif //__COID_SERVICES_HTTPSERV_MIME__HEADER_FILE__
